<?php
namespace BP\En;
class EntityTree extends Entity {
	public function getIsRoot () 
	{
		if (($this->getParentNo()->equals("-1") || $this->getParentNo()->equals("0")))
		{
			return  TRUE ;
		}
		if ($this->getNo()->equals($this->getParentNo()))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getNo () 
	{
		return $this->GetValStringByKey(EntityTreeAttr::$No);
	}
	public function setNo ($value) // [String value]
	{
		$this->SetValByKey(EntityTreeAttr::$No, $value);
	}
	public function getName () 
	{
		return $this->GetValStringByKey(EntityTreeAttr::$Name);
	}
	public function setName ($value) // [String value]
	{
		$this->SetValByKey(EntityTreeAttr::$Name, $value);
	}
	public function getParentNo () 
	{
		return $this->GetValStringByKey(EntityTreeAttr::$ParentNo);
	}
	public function setParentNo ($value) // [String value]
	{
		$this->SetValByKey(EntityTreeAttr::$ParentNo, $value);
	}
	public function getICON () 
	{
		return $this->GetValStringByKey(EntityTreeAttr::$ICON);
	}
	public function setICON ($value) // [String value]
	{
		$this->SetValByKey(EntityTreeAttr::$ICON, $value);
	}
	public function getIdx () 
	{
		return $this->GetValIntByKey(EntityTreeAttr::$Idx);
	}
	public function setIdx ($value) // [int value]
	{
		$this->SetValByKey(EntityTreeAttr::$Idx, $value);
	}
	public function getPK () 
	{
		return EntityTreeAttr::$No;
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($no) // [String no]
	{
		$me = new self();
		if ($DataType->IsNullOrEmpty($no))
		{
			throw new \RuntimeException(((($me->getEnDesc() . "@对表[") . $me->getEnDesc()) . "]进行查询前必须指定编号�??"));
		}
		$me->setNo($no);
		if (($me->Retrieve() == 0))
		{
			throw new \RuntimeException((((("@没有" . $me->get_enMap()->getPhysicsTable()) . ", No = ") . $me->getNo()) . "的记录�??"));
		}
		return $me;
	}
	abstract function ResetTreeNo (); 
	protected function beforeInsert () 
	{
		if (($this->getEnMap()->getIsAllowRepeatName() ==  FALSE ))
		{
			if (($this->getPKCount() == 1))
			{
				if (($this->ExitsValueNum("Name", $this->getName()) >= 1))
				{
					throw new \RuntimeException((((((("@插入失败[" . $this->getEnMap()->getEnDesc()) . "] 编号[") . $this->getNo()) . "]名称[") . $this->getName()) . "]重复."));
				}
			}
		}
		if ($DataType->IsNullOrEmpty($this->getNo()))
		{
			$this->setNo($this->GenerNewNoByKey("No"));
		}
		return parent->beforeInsert();
	}
	protected function beforeUpdate () 
	{
		if (($this->getEnMap()->getIsAllowRepeatName() ==  FALSE ))
		{
			if (($this->getPKCount() == 1))
			{
				if (($this->ExitsValueNum("Name", $this->getName()) >= 2))
				{
					throw new \RuntimeException((((((("@更新失败[" . $this->getEnMap()->getEnDesc()) . "] 编号[") . $this->getNo()) . "]名称[") . $this->getName()) . "]重复."));
				}
			}
		}
		return parent->beforeUpdate();
	}
	public function DoCreateSameLevelNode () 
	{
		$tempVar = $this->CreateInstance();
		$en = ( ($tempVar instanceof EntityTree) ? $tempVar : NULL );
		$en->setNo($String->valueOf(DBAccess->GenerOID($this)));
		$en->setName(("新建节点" . $en->getNo()));
		$en->setParentNo($this->getParentNo());
		$en->Insert();
		return $en;
	}
	public function DoCreateSubNode () 
	{
		$tempVar = $this->CreateInstance();
		$en = ( ($tempVar instanceof EntityTree) ? $tempVar : NULL );
		$en->setNo($String->valueOf(DBAccess->GenerOID($this)));
		$en->setName(("新建节点" . $en->getNo()));
		$en->setParentNo($this->getNo());
		$en->Insert();
		return $en;
	}
	public function DoUp () 
	{
		$this->DoOrderUp(EntityTreeAttr::$ParentNo, $this->getParentNo(), EntityTreeAttr::$Idx);
		return "执行成功.";
	}
	public function DoDown () 
	{
		$this->DoOrderDown(EntityTreeAttr::$ParentNo, $this->getParentNo(), EntityTreeAttr::$Idx);
		return "执行成功.";
	}
}
?>
